<?php
include_once('common/header.php');			
if($AppUI->id <=0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strLink		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if(!Vfriend_Function::isValidLink($strLink)) {
	Vfriend_Function::redirect(LINK_BLOG);
}
$intBlogId		= $objRequest->getParam('pblogid', '');
$intHexId		= $objRequest->getParam('puserid', 0);
$strName		= $objRequest->getParam('pname', '');
$strRefer		= $objRequest->getParam('prefer', '');
$oFile			= $_FILES['pimage'];
$strLinkMusic	= $objRequest->getParam('pmusic','');
$strContent		= $objRequest->getParam('pcontent','');
$intPerm		= $objRequest->getParam('pperm',0);
$intAcmt		= $objRequest->getParam('pacmt',0);
$strImage		= '';
$intError		= 0;
if($strName == '') $intError = 1;
elseif($strName != '' && strlen($strName) < 5) $intError = 2;
elseif($strLinkMusic != '' && !Vfriend_Function::isValidObject($strLinkMusic)) $intError = 4;
elseif(strip_tags($strContent) == '') $intError = 5;
elseif(strip_tags($strContent) != '' && strlen(strip_tags($strContent))<20) $intError = 6;
if($intError == 0 && isset($oFile['name']) && $oFile['name'] != '') {
	$arrImage = Globals::uploadBlog($oFile);	
	if($arrImage['error'] == "") {
		$strImage = $arrImage['path'];
	} else {
		$intError = 3;
	}
}
if($intError == 0) {
	if(isset($_SESSION['sBlogError'])) unset($_SESSION['sBlogError']);
	if(isset($_SESSION['sBlogEdit'])) unset($_SESSION['sBlogEdit']);
	$strShort 	= Vfriend_Function::wordCut($strContent);
	$objBlog	= new Blog();	
	$intError	= $objBlog->update($AppUI->id, $intBlogId, $strImage, $strName, Vfriend_Function::stripTags($strContent,5), $strShort, $strLinkMusic, $intPerm, $intAcmt);
	if($intError == 0) {
		Vfriend_Function::setMsg($arrMessage[2]);
		Vfriend_Function::redirect($strRefer);
	} else {
		$intError = 8;
	}
}
if($intError > 0) {
	$_SESSION['sBlogError']	= $arrError[$intError];
	$_SESSION['sBlogEdit']	= $objRequest->getParams();
	Vfriend_Function::redirect(LINK_BLOG_EDIT . '?blogid=' . $intBlogId . '&uid=' . $intHexId);
}
?>